package cn.wolfcode.luowowo.website.exceptionadvice;

import cn.wolfcode.luowowo.common.exception.LogicException;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/*
*
* 统一异常处理
*
* */
//@ControllerAdvice
public class CommonExceptionAdvice {

    @ExceptionHandler(LogicException.class)
    public void displayExp(Exception e, HttpServletResponse response)throws IOException{
        response.setContentType("test/json;charset=utf-8");
        response.getWriter().write(JSON.toJSONString(new AjaxResult(false,e.getMessage())));
    }

    @ExceptionHandler(RuntimeException.class)
    public void runTimeExp(Exception e,HttpServletResponse response)throws IOException{
        response.setContentType("test/json;charset=utf-8");
        response.getWriter().write(JSON.toJSONString(new AjaxResult(false,"系统出现异常，请联系管理员处理")));


    }

}
